<?php

namespace frontend\controllers\zyy;

use frontend\models\zyy\User;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\web\Request;
use yii\db\ActiveRecord;
use yii\db\Connection;
use Yii;
use yii\web\Response;
use  yii\db\Query;

class LoginController extends Controller
{
    public function actionLogin(Request $request){
        $data = $this->request->post();
//        $sql='select * from 2008a_user';
//        $results=User::findBySql($sql)->all();
        $results=User::find()->asArray()
//            ->select(['username','password'])
            ->where(['username'=>$data['username']])
            ->one();
//        var_dump($results);die();
//        $username=$request->post('username');
//        $password=$request->post('password');
        if ($results['username']==$data['username'] && $results['password']==$data['password']){
            return json_encode([
                'code'=>200,
                'msg'=>'登录成功',
                'data'=>[]
            ]);
        }else{
            return json_encode([
                'code'=>201,
                'msg'=>'登录失败',
                'data'=>[]
            ]);
        }
    }

}